<%-- 
    Document   : orderItem
    Created on : Apr 19, 2013, 12:16:24 PM
    Author     : Alexandra
--%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.Array"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="com.charlie.beans.Product"%>
<%@page import="java.util.List"%>
<%@page import="com.charlie.beans.ShipmentOrder"%>

<%@include file="/header.jsp" %>

<script>
    function isPositiveInteger(obj, value) {
        if (parseInt(obj.value) > 0) {
            obj.form.submit();            
        } else {
            obj.value = value;
            alert('You have input wrong value.');
        }
    }
</script>

<div class="left_side" >
    <jsp:include page="/blocks/conditionalLeftBar.jsp" /> 
</div>
<%
    ShipmentOrder item = (ShipmentOrder) getServletContext().getAttribute("order");
    if (item != null) {
        Map<Product, Integer> products = (HashMap<Product, Integer>) getServletContext().getAttribute("productsList");
        if (products != null) {
%>
<div class="right_side">
    <h2 class="content_title">View  cart (order #<%=item.getSoId()%>)</h2>
    <div class="white_block">
        <div class="ttl-Text">
            <h2> Selected items </h2>  
        </div>
        <table>
            <tbody>
                <tr class="underLinedRow"> 
                    <th> guitar </th>
                    <th> count </th>
                    <th> price </th>
                </tr>

                <%
                 if (request.getAttribute("item") != null) {
                    %>
                    <script>alert("There are no product items in the order. Please add some or cancel the order. ");</script>
                    <%
                 }
                for (Product p : products.keySet()) {%>

                <tr>

                    <td><%=p.getName()%> </td> 
                    <td>
                        <form method="post">
                            <input type="hidden" name="productToChange" value="<%=p.getProductId()%>">
                            <label for="number" id="labelForNumber"></label>
                            <input type="number" name="productCount" value="<%=products.get(p)%>" onchange="isPositiveInteger(this, <%=products.get(p)%>)">
                        </form>
                    </td>

                    <td>
                        <%=p.getCost()%>
                    </td>
                    <td>
                        <form method="post" name="removeProduct" action="${pageContext.request.contextPath}/warehouse/order">
                            <input name="idRemove" type="hidden" value="<%=p.getProductId()%>"> 
                            <input class="btn" value="Remove"  type="submit" >
                        </form>
                    </td>
                </tr>

                <%}%>  
                <tr>
                    <td class="rightAligment" colspan="4">
                        <form action="${pageContext.request.contextPath}/warehouse/products">
                            <input name="add" type="hidden" value="1">
                            <input class="btn" value="Add"  type="submit" > 
                        </form>
                    </td>

                </tr>
            </tbody>
        </table>

        <% if (products.size() > 0) {%>
        <div> Price : <%=item.getCost()%> + <%=item.getShipingCost()%> = <%=item.getShipingCost() + item.getCost()%> $</div> 
        <%}%>
        <div style="padding-top: 30px;">

            <label title="Comment" > Comment</label> 
            <form method="POST" name="Apply" action="${pageContext.request.contextPath}/warehouse/order">        
                <textarea name="commentForOrder" ROWS="10" cols="50" > </textarea>
                <input name="apply" type="hidden" value="<%=item.getSoId()%>>"> 
                <div class="rightAligment">
                    <input  class="btn"  value="Apply"  type="submit" > 
                    </form>
                    <form action="${pageContext.request.contextPath}/warehouse/order"  method="POST">
                        <input class="btn"  name="cancel" value="Cancel"  type="submit" > 
                    </form>

                </div>
        </div>
                        <%          }
    } else {
        out.print("<h1>No order</h1>");
    }%>
    </div>


</div>
    
<%@include file="/footer.jsp" %>
